﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdminApplication.ProductService;
using AdminApplication.CompanyService;
using AdminApplication.TypeService;
using AdminApplication.DomainService;


namespace AdminApplication
{
    public partial class frmProduct : Form
    {
        #region "Variables"
        private ProductServiceClient _productClient;
        private List<ProductDTO> _productList;
        #endregion

        #region "Properties"
        public ProductServiceClient ProductClient
        {
            get { return _productClient; }
            set { _productClient = value; }
        }
        public List<ProductDTO> ProductList
        {
            get { return _productList; }
            set { _productList = value; }
        }
        #endregion


        public frmProduct()
        {
            InitializeComponent();
            ProductClient = new ProductServiceClient();
            ProductList = new List<ProductDTO>();
            grviewProduct.Columns.Add("ProductID", "Mã sản phẩm");
            grviewProduct.Columns.Add("ProductName", "Tên sản phẩm");
            grviewProduct.Columns.Add("DomainName", "Tên Ngành");
            grviewProduct.Columns.Add("TypeName", "Tên Loại");
            grviewProduct.Columns.Add("CompanyName", "Tên NSX");
            grviewProduct.Columns.Add("Price", "Giá");
            grviewProduct.Columns.Add("ProPrice", "Giá KM");
            grviewProduct.Columns.Add("Unit", "ĐVT");
            grviewProduct.Columns.Add("Weight", "Trọng lượng");
            grviewProduct.Columns.Add("Quantity", "Số lượng");
            grviewProduct.Columns.Add("Info", "Thông tin");
            grviewProduct.Columns.Add("Image", "Ảnh");
            grviewProduct.Columns.Add("ImportDate", "Ngày Nhập");
            grviewProduct.Columns.Add("EndDate", "Hạn dùng");


        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            
        }

        private void splitContainer2_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }




        private void FillProducts()
        {
            try
            {
                ProductList.RemoveRange(0, ProductList.Count);
                ProductList.AddRange(ProductClient.GetAllProducts());

                foreach (ProductDTO item in ProductList)
                {
                    DataGridViewRow newRow = new DataGridViewRow();
                    newRow.Cells["ProductID"].Value = item.ProductID;
                    newRow.Cells["ProductName"].Value = item.ProductName;

                    //Get CompanyName
                    CompanyServiceClient companyClient=new CompanyServiceClient();
                    companyClient.SetID(item.CompanyID);
                    string CompanyName = companyClient.GetCompanyByID().CompanyName;
                    newRow.Cells["CompanyName"].Value = CompanyName;

                    //Get DomainName
                    DomainServiceClient domainClient = new DomainServiceClient();
                    domainClient.SetID(item.DomainID);
                    string DomainName = domainClient.GetDomainByID().DomainName;
                    newRow.Cells["DomainName"].Value = DomainName;

                    //Get TypeName
                    TypeServiceClient typeClient = new TypeServiceClient();
                    typeClient.SetID(item.TypeID);
                    string TypeName = typeClient.GetTypeByID().TypeName;
                    newRow.Cells["TypeName"].Value = TypeName;

                    newRow.Cells["Price"].Value = item.Price;
                    newRow.Cells["ProPrice"].Value = item.ProPrice;
                    newRow.Cells["Unit"].Value = item.Unit;
                    newRow.Cells["Weight"].Value = item.Weight;
                    newRow.Cells["Quantity"].Value = item.Quantity;
                }
            }

            catch
            {
            }


        }

        private void frmProduct_Load(object sender, EventArgs e)
        {
            FillProducts();
        }
    }
}
